
var staffPropertyInfo={

    init : function(cid,staffId,login_phone,name){


        staffPropertyInfo.cid = cid;
        staffPropertyInfo.staffId = staffId;
        staffPropertyInfo.login_phone = login_phone;
        staffPropertyInfo.name = name;
        staffPropertyInfo.click = 0;
        return staffPropertyInfo;
    },

    loadStaffProData:function(){
        var url = staffPropertyInfo.getPath() +"/aem/staffPropertyInfo/queryStaffPropertySetting";

        var data = {
            cid:staffPropertyInfo.cid,
            flag:1
        };
        var e = JSON.parse(staffPropertyInfo.syncAjax("post", url , data , false));
        if(e.status == "200"){
            var arr = e.data;

            var html_ = '';
            for(var i = 0 ; i < arr.length ; i ++){
               /* if(arr[i].keyName!='departmentId'){*/
                    if(arr[i].keyName == 'name'){
                        if(arr[i].edit == "0"){
                            html_ += '<li>' + arr[i].labelName + '<input placeholder="'+arr[i].labelContent+'"  class="'+arr[i].keyName+'" id="'+arr[i].keyName+'" data-required="'+arr[i].required+'" readonly></li>'
                        }else{
                            html_ += '<li>' + arr[i].labelName + '<input placeholder="'+arr[i].labelContent+'"  class="'+arr[i].keyName+'" id="'+arr[i].keyName+'" data-required="'+arr[i].required+'" ></li>'
                        }
                    }else if(arr[i].keyName == 'phone') {
                        if(arr[i].edit == "0"){
                            html_ += '<li>' + arr[i].labelName + '<div class="input-bg"><input readonly  class="' + arr[i].keyName + '" id="' + arr[i].keyName + '" data-required="'+arr[i].required+'" ><a><img src="' + path + '/images/aem/staffPropertyInfo.png" class="more"></a></div></li>'
                        }else{
                            html_ += '<li>' + arr[i].labelName + '<div class="input-bg"><input readonly  class="' + arr[i].keyName + '" id="' + arr[i].keyName + '" onclick="staffPropertyInfo.updateMobile()" data-required="'+arr[i].required+'" ><a><img src="' + path + '/images/aem/staffPropertyInfo.png" class="more"></a></div></li>'
                        }
                    }else if(arr[i].keyName == 'detailAddress'){
                        if(arr[i].edit == "0"){
                            html_ += '<li>' + arr[i].labelName + '<input placeholder="'+arr[i].labelContent+'" readonly  class="name" id="address" data-required="'+arr[i].required+'" data-edit="'+arr[i].edit+'"></li><li><input readonly placeholder="" style="margin-left: 0px" class="message address" id="'+arr[i].keyName+'" data-required="'+arr[i].required+'"></li>'
                        }else{
                            html_ += '<li>' + arr[i].labelName + '<input placeholder="'+arr[i].labelContent+'" readonly  class="name" id="address" data-required="'+arr[i].required+'" data-edit="'+arr[i].edit+'" ></li><li><input placeholder="" style="margin-left: 0px" class="message address" id="'+arr[i].keyName+'" data-required="'+arr[i].required+'"></li>'
                        }
                    }else if(arr[i].keyName == 'birthday'){
                        html_ += '<li>' + arr[i].labelName + '<input placeholder="'+arr[i].labelContent+'" readonly  class="name" id="birthday" data-required="'+arr[i].required+'" data-edit="'+arr[i].edit+'"></li>';
                    }else if(arr[i].keyName == 'departmentId'){
                        if(arr[i].edit == "0"){
                            html_ += '<li>' + arr[i].labelName + '<div class="input-bg"><input placeholder="请输入部门邀请码" style="margin-left: 0px" class="message" id="'+arr[i].keyName+'" readonly data-required="'+arr[i].required+'" ><a><img src="'+path+'/images/aem/staffPropertyInfo.png" class="more"></a></div></li>'
                        }else{
                            html_ += '<li>' + arr[i].labelName + '<div class="input-bg"><input placeholder="请输入部门邀请码" style="margin-left: 0px" class="message" id="'+arr[i].keyName+'" oninput="autoinput()" data-required="'+arr[i].required+'" ><a><img src="'+path+'/images/aem/staffPropertyInfo.png" class="more"></a></div></li>'
                        }
                    }else if(arr[i].keyName == 'sex'){
                        /*html_ += '<li>' + arr[i].labelName + '<div class="input-bg"><input readonly placeholder="'+arr[i].labelContent+'" style="margin-left: 0px" class="message" id="'+arr[i].keyName+'" data-required="'+arr[i].required+'" data-edit="'+arr[i].edit+'"></div></li>'*/
                        if(arr[i].edit=="0"){
                            html_ += '<li>' + arr[i].labelName + '<div class="input-bg sex"><input type="radio" id="male" name="sex" value="m" disabled style="margin-left: 0px;" class="message" data-required="'+arr[i].required+'"><span class="text male">男</span><input type="radio" id="female" name="sex" value="f" disabled style="margin-left: 0px;" class="message" data-required="'+arr[i].required+'"><span class="text">女</span></div></li>'
                        }else{
                            html_ += '<li>' + arr[i].labelName + '<div class="input-bg sex"><input type="radio" id="male" name="sex" value="m"  style="margin-left: 0px;" class="message" data-required="'+arr[i].required+'"><span class="text male">男</span><input type="radio" id="female" name="sex" value="f"  style="margin-left: 0px;" class="message" data-required="'+arr[i].required+'"><span class="text">女</span></div></li>'
                        }
                    }else{
                        if(arr[i].edit == "0"){
                            html_ += '<li>' + arr[i].labelName + '<div class="input-bg"><input readonly placeholder="'+arr[i].labelContent+'" style="margin-left: 0px; width:2.3rem;" class="message" id="'+arr[i].keyName+'" data-required="'+arr[i].required+'" ><a><img src="'+path+'/images/aem/staffPropertyInfo.png" class="more"></a></div></li>'
                        }else{
                            html_ += '<li>' + arr[i].labelName + '<div class="input-bg"><input placeholder="'+arr[i].labelContent+'" style="margin-left: 0px; width:2.3rem;" class="message" id="'+arr[i].keyName+'" data-required="'+arr[i].required+'" ><a><img src="'+path+'/images/aem/staffPropertyInfo.png" class="more"></a></div></li>'
                        }
                    }
              /*  }*/
            }
            $(".message-bg").append(html_);

          /*  //省市区三级联动
            if($("#detailAddress").length>0) {

                if($('#address').data('edit') == 1) {

                    var area1 = new LArea();
                    area1.init({
                        'trigger': '#address', //触发选择控件的文本框，同时选择完毕后name属性输出到该位置
                        'valueTo': '#value1', //选择完毕后id属性输出到该位置
                        'keys': {
                            id: 'id',
                            name: 'name'
                        }, //绑定数据源相关字段 id对应valueTo的value属性输出 name对应trigger的value属性输出
                        'type': 1, //数据源类型
                        'data': LAreaData //数据源
                    });
                    area1.value = [0, 0, 0];//控制初始位置，注意：该方法并不会影响到input的value
                }
            }

*/
            if($("#detailAddress").length>0) {
                if ($('#address').data('edit') == 1) {
                    window.initLocation('#address');
                }
            }

            //日期选择器
            if($("#birthday").length>0) {

                if($('#birthday').data('edit') == 1) {
                    var calendar = new LCalendar();
                    calendar.init({
                        'trigger': '#birthday', //标签id
                        'type': 'date', //date 调出日期选择 datetime 调出日期时间选择 time 调出时间选择 ym 调出年月选择,
                        'minDate': '1900-1-1', //最小日期
                        'maxDate': new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate() //最大日期
                    });
                }
            }

            //性别选择

           /* if($("#sex").length>0){
                if($('#sex').data('edit') == 1) {
                    var sexArr = ['男', '女'];
                    var sexSelect = new MobileSelect({
                        trigger: '#sex',
                        /!*title: '性别选择',*!/
                        wheels: [
                            {data: sexArr}
                        ],
                        transitionEnd: function (indexArr, data) {
                            console.log(data);
                        },
                        callback: function (indexArr, data) {
                            $('#sex').val(data);
                            console.log(data);
                        }
                    });
                }
            }*/
        }
    },



    loadPageParam : function(cid,staffId){
        var url = staffPropertyInfo.getPath() +"/aem/staffPropertyInfo/showStaffPropertyInfo";
        var data = {
            staffId:staffId,
            cid:cid,
        };
        var e = JSON.parse(staffPropertyInfo.syncAjax("post", url , data , false));
        if(e.status == "200"){
            var obj=e.data;
            $("#cid").val(obj.cid);

            $("#staffId").val(obj.staffId);
            if($("#name").length>0){
                $("#name").val(obj.userName);
            }
            if($("#phone").length>0){
                $("#phone").val(obj.mobile);
            }
            if($("#idCard").length>0){
                $("#idCard").val(obj.idCard);
            }
            if($("#departmentId").length>0){
                $("#departmentId").val(obj.organization);
                $("#deptId").val(obj.departmentId);
                staffPropertyInfo.click = 1;
                $("#oldOrgName").val(obj.organization);
                $("#oldOrgId").val(obj.departmentId);
            }

                if(obj.sex){

                    if(obj.sex == "m"){
                        $("#male").attr("checked","checked");
                    }else{
                        $("#female").attr("checked","checked");
                    }
                }

            if($("#birthday").length>0){

                $("#birthday").val(formatDateTimeYMD(obj.birthday));
            }
            if($("#email").length>0){
                $("#email").val(obj.email);
            }
            if($("#detailAddress").length>0){
                $("#detailAddress").val(obj.detailAddress);
                if(obj.provinceId){
                    var address = obj.provinceId+' '+obj.cityId + ' ' +obj.areaId;
                    $("#address").val(address);
                }

            }

        }
    },

    //修改手机页
    updateMobile : function () {
        window.location.href= staffPropertyInfo.getPath() + '/aem/staffPropertyInfo/staffMobile?phone=' + $('#phone').val() +'&staffId=' + staffPropertyInfo.staffId + '&cid=' + staffPropertyInfo.cid;
    },

    getPath : function(){
        var parse = staffPropertyInfo.parseUrl(window.location.href);
        var path = parse.protocol + '://' + parse.host + ':' + parse.port;
        if("scrm_sps" == parse.segments[0]){
            path +=  '/' + parse.segments[0];
        }
        return path;
    },

    trim : function(str) {
        return str.replace(/(^\s+$)/g, "");
    },

    isEmpty : function StringEmpty(content) {
        if (content == undefined || content == "" || content == null || content=="undefined" || content =="null") {
            return false;
        } else {
            return true;
        }
    },

    /**
     * 发送ajax请求
     *
     * type_ : post or get
     * url_ : url
     * data_ : data_
     * async_ : sync type ,true or false
     */
    syncAjax : function(type_, url_, data_  , async_) {
        var msg_ = null;
        $.ajax({
            dataType : "text",
            type : type_,
            url : url_,
            data : data_,
            async : async_,
            success : function(msg) {
                msg_ = msg;
            },
            error : function(msg) {
                msg_ = msg;
            }
        });
        return msg_;
    },

    parseUrl : function(url) {
        var a =  document.createElement('a');
        a.href = url;
        return {
            source: url,
            protocol: a.protocol.replace(':',''),
            host: a.hostname,
            port: a.port,
            query: a.search,
            params: (function(){
                var ret = {},
                    seg = a.search.replace(/^\?/,'').split('&'),
                    len = seg.length, i = 0, s;
                for (;i<len;i++) {
                    if (!seg[i]) { continue; }
                    s = seg[i].split('=');
                    ret[s[0]] = s[1];
                }
                return ret;
            })(),
            file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
            hash: a.hash.replace('#',''),
            path: a.pathname.replace(/^([^\/])/,'/$1'),
            relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
            segments: a.pathname.replace(/^\//,'').split('/')
        };
    },



}



